interface IEventBus {
  event: IEvent;
  on: (type: string, callback: Function) => void;
  emit: (type: string, params: {}) => void;
}
interface IEvent {
  [index: string]: Function[];
}

const EventBus: IEventBus = {
  event: {},
  on(type, callback) {
    if (!this.event[type]) {
      this.event[type] = [];
    }
    this.event[type].push(callback);
  },
  emit(type, params) {
    if (this.event[type]) {
      this.event[type].forEach((fn) => fn(params));
    }
  },
};
export default EventBus;
